package org.tloss.web.editor.model.oper.math;

public class ComplexOperand extends MathOperand {
	private MathOperand operand1;
	private MathOperand operand2;
	private MathOpertor operator;

	public ComplexOperand() {

	}

	public ComplexOperand(MathOperand operand1, MathOperand operand2,
			MathOpertor operator) {
		this.operand1 = operand1;
		this.operand2 = operand2;
		this.operator = operator;
	}

	public MathOperand getOperand1() {
		return operand1;
	}

	public void setOperand1(MathOperand operand1) {
		this.operand1 = operand1;
	}

	public MathOperand getOperand2() {
		return operand2;
	}

	public void setOperand2(MathOperand operand2) {
		this.operand2 = operand2;
	}

	public MathOpertor getOperator() {
		return operator;
	}

	public void setOperator(MathOpertor operator) {
		this.operator = operator;
	}

	@Override
	public String getDisplayText() {
		if (operator.supportTwoOperand())
			return "(" + operand1.getDisplayText() + " "
					+ operator.getDisplayText() + " "
					+ operand2.getDisplayText() + ")";
		else if (!operator.supportTail()) {
			return "" + operator.getDisplayText() + "("
					+ operand1.getDisplayText() + ")";
		} else {
			return "" + operand1.getDisplayText() + " "
					+ operator.getDisplayText();
		}
	}

	@Override
	public String generate(int type, Object[] param) {
		if (operator.supportTwoOperand())
			return "(" + operand1.generate(type, param) + " "
					+ operator.generate(type, param) + " "
					+ operand2.generate(type, param) + ")";
		else if (!operator.supportTail()) {
			return "" + operator.generate(type, param) + "("
					+ operand1.generate(type, param) + ")";
		} else {
			return "" + operand1.generate(type, param) + " "
					+ operator.generate(type, param);
		}
	}

	@Override
	public String getType() {
		return operand1.getType();
	}

}
